using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using System.Data;
using System.Data.OleDb;	

namespace BLL
{
    public class DiemthiDAL
    {
        public List<DIEMTHI> GetAll()
        {
            DIEMTHI diemthi;
            List<DIEMTHI> list = new List<DIEMTHI>();
            DataProvider dataprovider = new DataProvider();
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from DIEMTHI", null);
            for (int i = 0; i < datatable.Rows.Count; i++)
            {
                diemthi = new DIEMTHI();
                diemthi.Diem = Convert.ToByte(datatable.Rows[i]["Diem"]);
                list.Add(diemthi);
            }
            return list;
        }
        public DIEMTHI GetDIEMTHI(byte masinhvien)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@masinhvien", OleDbType.TinyInt);
            parameters[0].Value = masinhvien;
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from DIEMTHI where MaSV = @masinhvien", parameters);
            DIEMTHI diemthi = new DIEMTHI();
            if (datatable.Rows.Count != 0)
            {
                diemthi.Diem = Convert.ToByte(datatable.Rows[0]["Diem"]); ;
                return diemthi;
            }
            else
                return null;
        }

        public bool UpdateDIEMTHI(byte masinhvien, string mamon, string diem, byte diemcu)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[3];
            parameters[0] = new OleDbParameter("@masinhvien", OleDbType.TinyInt);
            parameters[0].Value = masinhvien;
            parameters[1] = new OleDbParameter("@mamon", OleDbType.Char);
            parameters[1].Value = mamon;
            parameters[2] = new OleDbParameter("@diem", OleDbType.Char);
            parameters[2].Value = diem;
            parameters[3] = new OleDbParameter("@diemcu", OleDbType.TinyInt);
            parameters[3].Value = diemcu;
            return dataprovider.ExecuteNonSelectQuery("update DIEMTHI set MaSV=@masinhvien, Mamon = @mamon, Diem = @diem where Diem = @diem", parameters);
        }
    }
}
